package logic

import (
	"context"
	"crypto/sha512"
	"github.com/anaskhan96/go-password-encoder"
	"strings"
	"user_srv/user_proto"
)

func (s *Server) CheckPassword(ctx context.Context, in *user_proto.CheckPasswordRequest) (*user_proto.CheckPasswordResponse, error) {
	options := &password.Options{
		SaltLen:      10,
		Iterations:   10000,
		KeyLen:       50,
		HashFunction: sha512.New,
	}
	split := strings.Split(in.EncryptedPassword, "$")
	check := password.Verify(in.Password, split[2], split[3], options)
	return &user_proto.CheckPasswordResponse{Success: check}, nil
}
